home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / nt_dsp2.lzh / NT_DSP2.MSA / BENCH / E-56.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-07-22  |  16.1 KB  |  374 lines

  1.      page 132,60,1,1  
  2.      opt  nomd,mex  
  3. ;*******************************************
  4. ;Motorola Austin DSP Operation  June 30,1988
  5. ;*******************************************
  6. ;DSP56000/1
  7. ;Port to Memory FFT - 256 point
  8. ;File name: E-56.asm
  9. ;**************************************************************************
  10. ;    Maximum sample rate:  458.2 us at 20.5 MHZ/ 347.9328.9 us at 27.0 MHz
  11. ;    Memory Size: Prog:  254 words ; Data:  1794 words
  12. ;    Number of clock cycles:    9394 (4697 instruction cycles)
  13. ;    Clock Frequency:    20.5MHz/27.0MHz
  14. ;    Instruction cycle time:    97.5ns /  74.1ns
  15. ;**************************************************************************
  16. ;
  17. ;
  18. fftreald  macro     points,data,odata,coef,ptr1,ptr2
  19. fftreald  ident     1,0   
  20. ;   
  21. ; Radix 2 Decimation in Time In-Place Fast Fourier Transform Routine   
  22. ;   
  23. ;    Real input data - normally ordered   
  24. ;        Real data in Y memory, 2 buffers: one being filled, the other one being processed
  25. ;    Complex output data - normally ordered   
  26. ;        Real data in X memory   
  27. ;        Imaginary data in Y memory   
  28. ;    Coefficient lookup table   
  29. ;        -Cosine value in X memory   
  30. ;        -Sine value in Y memory   
  31. ;   
  32. ; Macro Call - fftreald   points,data,outdata,coef,ptr1,ptr2
  33. ;   
  34. ;    points     number of points (2-32768, power of 2)   
  35. ;    data       start of data buffer   
  36. ;    outdata    output data buffer   
  37. ;    coef    start of sine/cosine table   
  38. ;    ptr1    memory location of pointer to input data block 1
  39. ;    ptr2    memory location of pointer to input data block 2
  40. ;
  41. ; Alters Data ALU Registers   
  42. ;    x1   x0   y1   y0   
  43. ;    a2   a1   a0   a   
  44. ;    b2   b1   b0   b   
  45. ;   
  46. ; Alters Address Registers   
  47. ;    r0   n0   m0   
  48. ;    r1   n1   m1   
  49. ;    r2   n2   m2
  50. ;    r3   n3   m3
  51. ;    r4   n4   m4   
  52. ;    r5   n5   m5   
  53. ;    r6   n6   m6   
  54. ;    r7   n7   m7
  55. ; Alters Program Control Registers   
  56. ;    pc   sr   
  57. ;   
  58. ; Uses 8 locations on System Stack   
  59. ;   
  60. _intdata  equ $0    ;internal data space at 0 
  61. ;
  62. ;Check r7 to see if input buffer is filled
  63. ;
  64. strt move #points,b ;input buffer length
  65. loop move r7,a      ;get input data pointer
  66.      sub  a,b       ;subtract buffer length from current input location
  67.      move x:ptr1,a  ;move input data base addres into a
  68.      cmp  a,b       ;see if equal
  69.      jne  loop      ;if not, go back
  70. ;
  71. ;    when ready, swap pointers of buffer to be loaded and buffer to be processed
  72. ;
  73.      move x:ptr1,a
  74.      move x:ptr2,b
  75.      move b,x:ptr1
  76.      move a,x:ptr2
  77. ;
  78. ;    main fft routine
  79. ;
  80.      move x:ptr2,r2         ;initialize input pointers   
  81.      move #4,n2             ;initial offset for r2
  82.      move r2,r0             ;input pointer for real passes
  83.      move (r2)+n2           ;update external input pointer for complex passes
  84.      move #points/4,n0       ;initialize input and output offsets   
  85.      move #points-1,m0       ;initialize address modifiers for modulo N   
  86.      move r0,r4               ;set up butterfly pointers in and out
  87.      move (r0)+n0              ;
  88.      move r0,r5              ;
  89.      move (r0)+n0              ;
  90.      move r0,r1              ;
  91.      move r4,r0              ;
  92.      move m0,m1              ;modulo N for remaining pointers in and out
  93.      move m0,m4              ;
  94.      move m0,m5              ;
  95. ;  
  96. ; Do first and second Radix 2 FFT passes: all have real input. First and second
  97. ; passes are combined using four-point butterflies.
  98.      move                   y:(r0)+n0,a         ;get ar  
  99.      move                   y:(r0)+n0,y1        ;get br  
  100.      move                   y:(r0)+n0,b         ;get cr  
  101.      add  a,b               y:(r0)+n0,y0        ;(ar+cr),get dr  
  102.      subl b,a                                  ;cr'=(ar-cr)  
  103.      do   n0,_twopass                          ;do all four point butterflies
  104.      tfr  y0,a      a,x:(r1)                  ;get dr,save cr'  
  105.      sub  y1,a      (r0)+                      ;ci'=(dr-br)  
  106.      tfr  y1,a              a,y:(r1)+         ;get br,save ci'  
  107.      add  y0,a              y:(r0)+n0,x1        ;(br+dr),get ar  
  108.      add  b,a               y:(r0)+n0,y1       ;ar'=(ar+cr)+(br+dr),get br  
  109.      subl a,b               a,y:(r4)+         ;br'=(ar+cr)-(br+dr),save ar'  
  110.      tfr  x1,a              b,x0 y:(r0)+n0,b    ;get ar,move br',get cr  
  111.      add  a,b               y:(r0)+n0,y0       ;(ar+cr),get dr  
  112.      subl b,a       x0,x:(r5)+                 ;cr'=(ar-cr),save br'  
  113. _twopass  
  114. ;  
  115. ; Do next real-input FFT (RFFT) passes. Each RFFT butterfly is a four-point in,
  116. ; 3-point out. The fourth point is not computed since it is later obtained by
  117. ;using the conjugate symmetry property of the RFFT.
  118. ;
  119.      move #points/8,n5                        ;spacing, for 1024 spacing=128  
  120.      do   #@cvi(@log(points)/@log(2)-2.5),_next   ;7 passes for 1024 pts  
  121.      move #data,r5                             ;point to data   
  122.      move n5,n0                                 ;same offset  
  123.      move r5,r0                                 ;ar pointer  
  124.      move (r5)+n5                               ;+1/4  
  125.      move r5,r4                                 ;br pointer  
  126.      move (r5)+n5                               ;+1/2  
  127.      move r5,r1                                 ;ci pointer  
  128.      move (r5)+n5                               ;+3/4  
  129.      move                    y:(r0)+n0,a           ;get ar  
  130.      move                    y:(r0)-n0,b           ;get br  
  131.      add  a,b                                  ;ar'=(ar+br)  
  132.      do   n0,_nextpass                          ;do for all p
  133.      subl b,a  x:(r5)+,b     b,y:(r0)+         ;br'=(ar-br),get dr,save ar'  
  134.      neg  b    a,x:(r4)+     y:(r0)+n0,a        ;ci'=-dr,save br',get ar  
  135.      move b,x0              y:(r0)-n0,b        ;move ci',get br  
  136.      add  a,b                x0,y:(r1)+         ;ar'=(ar+br),save ci'  
  137. _nextpass  
  138.      move n5,a                                 ;get bflys/pass  
  139.      lsr  a                                    ;/2  
  140.      move a1,n5                                 ;put back  
  141. _next  
  142. ;  
  143. ;    special RFFT pass: real input, (4-point). Complex output: stored in normal
  144. ;    order, 4-th output stored as complex conjugate of 3rd output.
  145. ;    
  146. ;  
  147.      move #data,r0                             ;input pointer  
  148.      move #odata,r4                            ;output pointer  
  149.      move #points/2,n4                          ;output pointer offset
  150.      move #0,m4                                 ;bit reverse output  
  151.      move                     y:(r0)+,a            ;get ar  
  152.      move                     y:(r0)+,b            ;get br  
  153.      add  a,b    x:(r0)+,x0                       ;ar'=ar+br, get cr  
  154.      move      b,x:(r4)+n4                     ;save ar'
  155.      subl b,a  x:(r0),b                       ;br'=ar-br, get dr
  156.      neg  b    b,y0           a,x:(r4)+n4        ;ci'=-dr, save dr, save br'  
  157.      move      x0,x:(r4)                      ;save cr'  
  158.      move                     b,y:(r4)+n4          ;save ci'  
  159.      move      x0,x:(r4)                      ;save cr'  
  160.      move                      y0,y:(r4)+n4         ;save cr,ci'*  
  161. ;    do first 2-point complex fft with conjugate storage 
  162. ;    initialization 
  163.      move      r2,r0              ;r0 points to external data 
  164.      move      #-1,m2             ;linear addr. for external input data pointer 
  165.      move      #4,n2              ;offset for external input data pointer 
  166.      move      #points/8,r3       ;coefficient base offset -->r3 
  167.      move      (r2)+n2            ;update external input data pointer 
  168.      lua       (r0)+,r1           ;initialize input pointer b 
  169.      lua       (r3)+n3,r6         ;initialize twiddle factor pointer 
  170.      move      #points/4,n4       ;offset for output counter a 
  171.      move      r4,n3              ;initialization of conjugate pointer 
  172.      move      #odata+points,r3    ; 
  173.      move      r4,r5               ;initialize output pointer b 
  174.      move      (r3)-n3             ;initialize conjugate pointer 
  175.      move      #odata,n3           ; 
  176.      lua       (r4)+n4,r5          ;initialize output pointer b 
  177.      move      (r3)+n3             ;initialize conjugate pointer 
  178.      move      n4,n5               ;initialize offset for output pointer b 
  179.      move      #0,m4               ;bit-reversed addressing for output ptr a 
  180.      move      (r5)+n5             ;initialize output pointer b 
  181.      move      #0,m5               ;bit-reversed addressing for output ptr b 
  182.      move      #0,m3               ;bit-reversed addressing for conjug. ptr. 
  183.      move      #points/2,n3        ;offset for conjugate pointer 
  184.      move                y:(r0),b  ;initialize butterfly 
  185.      move      (r3)+n3             ;future output pointer a 
  186.      move      r3,ssh              ;save future output pointer a -->stack 
  187.      move      (r3)-n3             ;reinit. conjugate pointer 
  188. ;
  189. ;    butterfly with conjugate storage    
  190. ;
  191.      move           x:(r1),x1 y:(r6),y0  
  192.      mac  x1,y0,b   x:(r6),x0 y:(r1),y1 
  193.      macr -x0,y1,b            y:(r0),a 
  194.      neg  b                   b,y:(r4)        
  195.      move                     b,y:(r3)-n3 
  196.      addl b,a       x:(r0),b   
  197.      neg  a                   a,y:(r5) 
  198.      move                     a,y:(r3)+n3 
  199.      mac  -x1,x0,b  x:(r0),a   
  200.      macr -y1,y0,b   
  201.      subl b,a       b,x:(r4)+n4 
  202.      move           b,x:(r3)-n3 
  203.      move           a,x:(r5)+n5 
  204.      move           a,x:(r3)-n3               
  205. ;    end of butterfly 
  206. ;
  207. ;    initialize pointers for complex fft's
  208. ;
  209.      move      #coef,n3  ;initialize coefficient base 
  210.      move      #-1,m3 
  211.      move      m3,m4     ;output pointer a has linear addr. 
  212.      move      m3,m5     ;output pointer b has linear addr. 
  213.      move      ssh,r4    ;initialize next external output pointer a position     
  214.      move      #2,m2     ;initialize butterflies per group 
  215.      move      #1,n4     ;initialize number of passes-1 per FFT 
  216. ;
  217. ;    do all the complex fft's that are necessary (up to N/4-point)
  218. ;
  219.      do   #@cvi(@log(points)/@log(2)-2.5),_end_fft     ;7 for 1024 pt (4- pt....256- pt)  
  220. ;
  221. ;    initialize pointers in each fft
  222.      move      r4,ssh    ;push output data address onto stack 
  223.      move r2,r0          ;get external data input address for first pass 
  224.      move #points/8,r3   ;update coefficient offset 
  225.      move m2,n1          ;initialize butterflies per group 
  226.      move #1,n2          ;initialize groups per pass 
  227. ;    complex fft passes are triple nested do-loops, with last pass split out 
  228.      do   n4,_end_pass   ;do all passes but last in this fft 
  229. ;
  230. ;    initialize pointers in each pass
  231.      move n4,ssh         ;put number of passes-1 in FFT on stack 
  232.      move #_intdata,r4   ;initialize A output pointer 
  233.      move n1,r5 
  234.      move n1,n0          ;initialize pointer offsets 
  235.      lua  (r5)-,n7 
  236.      move n1,n4 
  237.      move n1,r6 
  238.      lua  (r0)+n0,r1     ;initialize B input pointer 
  239.      lua  (r4)+n4,r5     ;initialize B output pointer 
  240.      lua  (r6)+,n4 
  241.      move n4,n5 
  242.      lua  (r3)+n3,r6     ;initialize W input pointer 
  243.      move n4,n0 
  244. ;    
  245. ;    initialize butterfly input
  246.      move         x:(r1),x1     y:(r6),y0        ;lookup -sine value 
  247.      move                       y:(r0),b         ;imag. input a
  248.      mac  x1,y0,b   x:(r6)+n6,x0   y:(r1)+,y1     ;cos., imag. input b
  249.      macr -x0,y1,b                y:(r0),a       ;
  250. ;
  251. ;    butterflies
  252.      do   n2,_end_grp                        ;do for all groups                         
  253.      do   n7,_end_bfy                         ;do every butterfly in this group
  254.      subl b,a       x:(r0),b      b,y:(r4)
  255.      mac  -x1,x0,b  x:(r0)+,a     a,y:(r5)
  256.      macr -y1,y0,b  x:(r1),x1
  257.      subl b,a       b,x:(r4)+     y:(r0),b
  258.      mac  x1,y0,b                  y:(r1)+,y1     ;Radix 2 DIT butterfly kernel
  259.      macr -x0,y1,b  a,x:(r5)+     y:(r0),a      ;with constant twiddle factor
  260. _end_bfy             
  261.      move (r1)+n1
  262.      subl b,a       x:(r0),b      b,y:(r4)
  263.      mac  -x1,x0,b  x:(r0)+n0,a    a,y:(r5)
  264.      macr -y1,y0,b  x:(r1),x1     y:(r6),y0      ;lookup -sine value
  265.      subl b,a       b,x:(r4)+n4    y:(r0),b
  266.      mac  x1,y0,b   x:(r6)+n6,x0   y:(r1)+,y1
  267.      macr -x0,y1,b  a,x:(r5)+n5    y:(r0),a      ;with constant twiddle factor
  268. _end_grp            
  269.      move n1,b1
  270.      lsr  b    n2,a1                         ;divide butterflies per group by two
  271.      lsl  a    b1,n1                         ;multiply groups per pass by two
  272.      move      r3,b1
  273.      move      ssh,n4                        ;get number of passes-1 back from stack
  274.      lsr  b    a1,n2                         ;divide coefficient offset by two
  275.      move      b1,r3
  276.      move      #_intdata,r0                   ;intermediate passes use internal input data
  277. _end_pass
  278. ;        
  279. ; Do last FFT pass and move output data off-chip to external data memory.
  280. ; The output data is stored in normal order. At the same time, data is stored for
  281. ; the next output block using conjugate properties and a "reverse counter"
  282. ;
  283. ;    initialize pointers
  284.      move n7,r1
  285.      move ssh,r4
  286.      move (r1)+
  287.      move n4,ssh                    ;put #passes-1 in this fft back on stack
  288.      move r1,n0
  289.      move r1,n1                        ;correct pointer offset for last pass
  290.      move r1,n4
  291.      move r1,n5
  292.      move #points/4,n4                  ;offset for output pointer A 
  293.      lua  (r0)+,r1                  ;initialize B input pointer        
  294.      lua  (r4)+n4,r5                 ;initialize B output pointer, first step
  295.      move  n4,n5                          ;offset for output pointer B 
  296.      lua  (r3)+n3,r6                 ;initialize W input pointer
  297.      move (r5)+n5                        ;initialize B output pointer, second step
  298.      move #0,m4                         ;bit-reversed addressing for output pointer A
  299.      move r4,n3                       ;initialization of conjugate pointer
  300.      move #odata+points,r3            
  301. ;
  302. ;    initialize butterfly
  303.      move                    y:(r0),b          ;initialization of first butterfly
  304.      move      (r3)-n3                         ;initialization of conjugate pointer    
  305.      move      #odata,n3                       ;
  306.      move      x:(r1),x1     y:(r6),y0         ;initialization of first butterfly
  307.      move      (r3)+n3                         ;initialization of conjugate pointer
  308.      move      #0,m3                           ;bit-reversed addressing for conjugate ptr
  309.      move      #points/2,n3                    ;correct offset for conjugate pointer
  310.      move      m4,m5                           ;bit-reversed addressing for output pointer B     
  311.      move      (r3)+n3
  312.      move      r3,ssh                           ;put next output ptr a initialization on stack
  313.      move      (r3)-n3                         ;reset conjugate pointer
  314. ;
  315. ;    final butterfly with conjugate reverse storage of next block
  316.      do   n2,_lastpass
  317.      mac  x1,y0,b   x:(r6)+n6,x0   y:(r1)+n1,y1   ;Radix 2 DIT butterfly kernel
  318.      macr -x0,y1,b                 y:(r0),a       ;with one butterfly per group                     
  319.      neg b                         b,y:(r4)       ;and changing twiddle factor
  320.      move                          b,y:(r3)-n3    ;with conjugate storage
  321.      addl b,a  x:(r0),b  
  322.      neg a                         a,y:(r5)
  323.      move                          a,y:(r3)+n3
  324.      mac  -x1,x0,b  x:(r0)+n0,a    
  325.      macr -y1,y0,b  x:(r1),x1      y:(r6),y0
  326.      move           b,x:(r4)+n4
  327.      subl b,a       b,x:(r3)-n3    
  328.      move           a,x:(r5)+n5    y:(r0),b
  329.      move           a,x:(r3)-n3
  330. _lastpass
  331. ;
  332. ;    update pointers
  333.      move ssh,r4        ;get updated output ptr a from stck for next fft
  334.      move #coef,n3      ;n3 points to coeff. base address again
  335.      move #-1,m3        ;linear addressing for r3 again
  336.      move n6,n2          ;get fft data input offset
  337.      move m2,a           ;initial data offset-->a
  338.      move ssh,r6        ;get #passes in FFT-1 back from stack
  339.      lsl  a              ;initial data offset * 2 -->a
  340.      move #-1,m6        ;r6 increments linearly in next instruction
  341.      move #-1,m2        ;external data pointer uses linear addressing
  342.      lua (r6)+,n4          ;increment #passes-1 -->n4
  343.      move #0,m6         ;r6 increments bit-reversed again
  344.      move a1,r6         ;new initial data offset-->r6
  345.      lsl a                 ;2*#points in this fft -->a
  346.      move a1,n2         ;offset for new external input data
  347.      move m0,m4         ;initialize output pointers again for modulo addr.
  348.      move m0,m5         ;
  349.      move (r2)+n2       ;point to next complex fft input data block
  350.      move      r6,m2     ;new initial data offset for next FFT-->m2
  351. _end_fft
  352. ;
  353. ;    when fft is finished, jump back to see if data collection for next fft is completed
  354.      jmp  strt           
  355.      endm
  356. ;;
  357. ;
  358. ;
  359. ;
  360. ;
  361.      org p:$8
  362.      movep     y:$ffff,y:(r7)+        ;data collection upon interrupt
  363.      org p:$100                
  364.      move #64,a                    
  365.      move a,x:$340                    ;store pointer to data block 1
  366.      move #320,a
  367.      move a,x:$341                    ;store pointer to data block 2
  368.      move #511,m7                        ;set r7 for modulo addressing
  369. ;
  370. ;    call fft macro
  371.      fftreald 256,$40,$240,$342,$340,$341 ə                                                                                      
  372.